package logic

import (
	"context"
	"zc2/model/mysql"
	"zc2/userrpc/internal/svc"
	"zc2/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *userrpc.AddGoodsRequest) (*userrpc.AddGoodsResponse, error) {
	// todo: add your logic here and delete this line

	product := mysql.Product{
		Title:  in.Title,
		Des:    in.Des,
		Price:  in.Price,
		UserId: int(in.Userid),
	}
	mysql.DB.Create(&product)
	return &userrpc.AddGoodsResponse{Id: int64(product.ID)}, nil
}
